<template>
<el-col :span="24">
  <el-row> 
    <el-col :span="24"><div class="grid-content">
      <el-col :span="12">
        <el-input v-model="filters[0].value" placeholder="搜索框"></el-input>  
      </el-col>
     <el-button type="primary" @click="dialogFormVisible1 = true">新增条目</el-button>

  <data-tables :data="data" :filters="filters" :action-col="actionCol"> -->
      <template v-for="(item,index) in titles">
      <el-table-column :prop="item.prop" :label="item.label"  :key="index" v-if="item.prop === 'version'" width="60px" ></el-table-column>
      <el-table-column :prop="item.prop" :label="item.label"  :key="index" v-if="item.prop === 'name'"    width="200px" ></el-table-column>
      <el-table-column :prop="item.prop" :label="item.label"  :key="index" v-if="item.prop != 'version' && item.prop != 'name'" :show-overflow-tooltip="true"></el-table-column>
      </template>
  </data-tables> 
  
      </div></el-col>
  </el-row>


  <el-dialog title="详细信息" :visible.sync="dialogFormVisible">
    <el-form :model="form">
      <el-form-item label="用户名" :label-width="formLabelWidth"> 
        <el-input v-model="form.name"   autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="私钥" :label-width="formLabelWidth">
        <el-input v-model="form.private" type="textarea"  rows="9" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="公钥" :label-width="formLabelWidth">
        <el-input v-model="form.public"  type="textarea"  rows="5" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="版本" :label-width="formLabelWidth">
        <el-input v-model="form.version"   autocomplete="off"></el-input>
      </el-form-item>      
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="dialogFormVisible= false">关闭</el-button>
      <!-- <el-button type="primary" @click="input">确 定</el-button> -->
    </div>
  </el-dialog>

  <el-dialog title="新增字段" :visible.sync="dialogFormVisible1">
    <el-form :model="form1">
      <el-form-item label="用户名" :label-width="formLabelWidth">
        <el-input v-model="form1.name"   autocomplete="off"></el-input>
      </el-form-item>

      <el-form-item label="自动生成密钥" :label-width="formLabelWidth">
        <el-switch v-model="form.delivery" @change="isDisabled"></el-switch>
      </el-form-item>

      <el-form-item label="私钥" :label-width="formLabelWidth">
        <el-input v-model="form1.private" :disabled="isdisabled" type="textarea"  rows="9" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="公钥" :label-width="formLabelWidth">
        <el-input v-model="form1.public"  :disabled="isdisabled" type="textarea"  rows="5" autocomplete="off"></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="dialogFormVisible1 = false">取 消</el-button>
      <el-button type="primary" @click="input1">确 定</el-button>
    </div>
  </el-dialog>

  
</el-col>

</template>

<script>
import { url, UrlPost, UrlDel } from '@/api/query'
// import  qs from 'qs';
export default {
  data() {
    return {
      isdisabled:true,
      show: true,
      dialogFormVisible: false,
      dialogFormVisible1: false,
      form: {
          name: '',
          private: '',
          public:'',
          version:'',
          delivery: true,
          type: [],
          resource: '',
          desc: ''
        },
      form1: {
          name: '',
          private: '',
          public:'',
          delivery: false,
          type: [],
          resource: '',
          desc: ''
        },
        formLabelWidth: '120px',
      data: [
      ],
      titles: [{
        prop: 'name',
        label: '用户名'
      },{
        prop: 'private',
        label: '私钥(解密)'
      },{
        prop: 'public',
        label: '公钥(加密)'
      },{
        prop: 'version',
        label: '版本'
      }],
      actionCol: {
              label: '操作',
              props: {
                align: 'center',
              },
              buttons: [
                {
                props: {
                  type: 'primary',
                  icon: 'el-icon-edit'
                },
                handler: row => {
                  this.dialogFormVisible = true
                  console.log(row);
                  this.form.name = row.name
                  this.form.private = row.private
                  this.form.public = row.public
                  this.form.version = row.version

                },
                label: '详情'
              },
              //  {
              //   handler: row => {
              //     this.data.splice(this.data.indexOf(row), 1),
              //     console.log(row.name)
              //     this.$message('dep_name: '+row.name+'删除完毕')
              //     var param={dep_name : row.name}
              //     console.log(param);
              //     UrlDel(param).then(response => {
              //     console.log(response.data)
              //       // location.reload();
              //     this.url()
              //     })
              //   },
              //   label: 'delete'
              // }
              ]
            },
      filters: [
        {
          prop: 'name',
          value: '',       
        }
      ],
      
    }
  },
  created() {    
    this.url()  
  },
	methods: {
		isDisabled(){
			this.isdisabled = !this.isdisabled;
		},
    url() {
      url().then(response => {
        console.log(response.data)
        this.data = response.data
      })
    },
    // input() {
    //   UrlPost({ "dep_name": this.form.name,"dep_private": this.form.private,"dep_public":this.form.public }).then(response => {
    //     console.log(response.data)
    //     this.dialogFormVisible = false
    //     this.url()
    //   })
    // },
    input1() {
      UrlPost({ "dep_name": this.form1.name,"dep_private": this.form1.private,"dep_public":this.form1.public}).then(response => {
        console.log(response.data)
        this.dialogFormVisible1 = false
        this.url()
      })
    },

},
}
</script>
<style>
 .el-tooltip__popper{max-width:25%}
</style>